feat(pages): add select_foreground_page tool to detect and select the visible browser tab#2356
Open
santhreal wants to merge 1 commit into
Open
feat(pages): add select_foreground_page tool to detect and select the visible browser tab#2356santhreal wants to merge 1 commit into
santhreal wants to merge 1 commit into
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
santhreal
force-pushed
the
feat/select-foreground-page
branch
from
July 13, 2026 11:00
1bf9505 to
921194b
Compare
… visible browser tab (ChromeDevTools#933) When connecting to an existing browser with --autoConnect, the MCP-selected page may differ from the tab the user is actually looking at. The new select_foreground_page tool queries document.visibilityState across all open pages and selects the one that is currently in the foreground. This avoids the need for the user to manually list_pages + select_page when they simply want to work with whatever tab is currently open in the browser.
santhreal
force-pushed
the
feat/select-foreground-page
branch
from
July 13, 2026 11:13
921194b to
2498c49
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a new
select_foreground_pagetool that detects and selects the browser tab currently visible to the user.Fixes #933
Problem
When connecting to an existing browser with
--autoConnect, the MCP-selected page often doesn't match the tab the user is actually looking at. The[selected]tag inlist_pagesreflects MCP's internal selection (defaults topages[0]), not the browser's foreground tab. Users have to:list_pagesselect_pagewith the correct IDSolution
The new
select_foreground_pagetool queriesdocument.visibilityStateon every open page viapage.evaluate(). If exactly one page reports"visible", it is automatically selected.Why
document.visibilityState?bringToFront()correctly updates it"visible"and background tabs report"hidden"Graceful fallback
If visibility can't be determined (e.g. all pages hidden, multiple visible, or
evaluate()fails onchrome://pages), the tool reports failure and suggests usingselect_pagemanually.Changes
src/McpContext.tsselectForegroundPage()methodsrc/tools/pages.tsselect_foreground_pagetool definitionsrc/tools/ToolDefinition.tsselectForegroundPagetoContexttypesrc/bin/chrome-devtools-cli-options.tstests/tools/pages.test.tsExample workflow